package com.betterjr.modules.risk.loanmanage;

import static com.betterjr.common.web.ControllerExceptionHandler.exec;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.web.Servlets;

@Controller
@RequestMapping("/Scf/LoanManage")
public class LoanManageController {

    private static final Logger logger = LoggerFactory.getLogger(LoanManageController.class);

    @Reference(interfaceClass = ILoanManageService.class)
    private ILoanManageService loanManageService;

    @RequestMapping(value = "/saveLoanData", method = RequestMethod.POST)
    public @ResponseBody String saveLoanData(final HttpServletRequest request) {
        logger.info("保存放款数据");
        final Map<String, Object> param = Servlets.getParametersStartingWith(request, "");
        return exec(() -> loanManageService.saveLoanData(param), "保存放款数据失败", logger);

    }

    @RequestMapping(value = "/queryLoanDataByPage", method = RequestMethod.POST)
    public @ResponseBody String queryLoanDataByPage(final HttpServletRequest request, final int pageNum,
            final int pageSize, final String flag) {
        logger.info("分页放款数据");
        final Map<String, Object> param = Servlets.getParametersStartingWith(request, "");
        return exec(() -> loanManageService.listLoanDataByPage(param, pageNum, pageSize, null), "分页放款数据失败", logger);

    }

    /** 
     * @Title: manuallyCompletedRePayment 
     * @Description: 账户监管界面，已扣清，   手动结清还款
     * @param request
     * @return 
     * @throws 
     * @author licz
     * @date 2018年6月26日 下午5:11:10 
     */
    @RequestMapping(value = "/manuallyCompletedRePayment", method = RequestMethod.POST)
    public @ResponseBody String manuallyCompletedRePayment(final HttpServletRequest request, final long id) {
        logger.info("手动结清还款");
        return exec(() -> loanManageService.manuallyCompletedRePayment(id), " 手动结清还款失败", logger);

    }

}
